package com.github.ginirohikocha;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Random;

import com.github.ginirohikocha.bean.Database;

public class InsertRandomTemp {
	
	public static void main(String[] args) {
		Random random = new Random(System.currentTimeMillis());
		
		Database db = new Database();
		Connection dbCon = db.getDbCon();
		PreparedStatement pstmt;
		try {
			while(true) {
				pstmt = dbCon.prepareStatement("INSERT INTO temperature VALUES(CURDATE(),CURTIME(),?)");
				pstmt.setShort(1, (short)(random.nextInt(21)+10));
				pstmt.executeUpdate();
				Thread.sleep(5000);
			}
		} catch (SQLException | InterruptedException e) {
			e.printStackTrace();
		}
	}
}
